import { randomInt } from ".";
export const getRandomItem = (array: any[]) => {
    return array[randomInt(0, array.length - 1)]
}
export const chunk = <T>(array: T[], size: number = 1): T[][] => {
    if (size <= 0) return [];
    const result = [];
    for (let i = 0; i < array.length; i += size) {
        result.push(array.slice(i, i + size))
    }
    return result
}

export const createEmpty2DArray = <T>(rows: number, cols: number = rows, initialValue: T = 0 as unknown as T): T[][] => {
    return Array.from({ length: rows }, () => Array.from({ length: cols }, () => initialValue))
}
export const createRandom2DArray = (rows: number, cols: number = rows, min: number = 0, max: number = 100): number[][] => {
    const array: number[][] = [];
    for (let i = 0; i < rows; i++) {
        array[i] = [];
        for (let j = 0; j < cols; j++) {
            array[i][j] = randomInt(min, max);
        }
    }
    return array;
}